<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Create account form template
 *
 * @see app/design/frontend/base/default/template/customer/form/register.phtml
 */
/** @var $this Mage_Customer_Block_Form_Register */
?>
<div class="account-create">
    <div class="page-title">
        <h1><?php echo $this->__('Create Your Account') ?></h1>
    </div>
    <?php echo $this->getChildHtml('form_fields_before')?>
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
  <div class="introduce">
    <p>
		<strong>GobblerShop.com Customers Save More!</strong><br/>
		Register today to start shopping smarter with our monster savings! You'll also be kept in the loop for our awesome monthly offers.
    </p>
  </div>
    <form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
		<div class="register-form form-container">
			<?php if($groupId = $this->getRequest()->getParam('group_id')):?>
			<input type="hidden" name="group_id" value="<?php echo $groupId?>"/>
			<?php endif?>
			<h2 class="legend"><?php echo $this->__('Account infomation') ?></h2>
			<div class="fieldset">
			<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
			<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
			<ul class="form-list">
				<li>
					<?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
				</li>
				<li>
					<label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
					<div class="input-box">
						<input type="text" name="email" id="email_address" value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-domain-email required-entry" />
						<img class="passed" src="<?php echo $this->getSkinUrl('images/check.png')?>"/>
					</div>
				</li>
				<li>
				  <label for="email_address_confirm" class="required"><em>*</em><?php echo $this->__('Confirm Email Address') ?></label>
				  <div class="input-box">
					<input type="text" name="email_confirm" id="email_address_confirm" value="<?php echo $this->escapeHtml($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Confirm Email Address') ?>" class="input-text validate-domain-email validate-email-confirm required-entry" />
					<img class="passed" src="<?php echo $this->getSkinUrl('images/check.png')?>"/>
				  </div>
				</li>
				<li>
				  <label for="password" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
				  <div class="input-box">
					<input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
				  </div>
				</li>
				<li>
				  <label for="confirmation" class="required"><em>*</em><?php echo $this->__('Confirm Password') ?></label>
				  <div class="input-box">
					<input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
				  </div>
				</li>
				<?php if ($this->isNewsletterEnabled() || true): ?>
				<li class="control">
					<div class="input-box">
						<input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($this->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" />
					</div>
					<label for="is_subscribed"><?php echo $this->__('Please include me in the GobblerShop.com mailing list for future promotions') ?></label>
				</li>
				<?php endif ?>
			</ul>        
			<div class="accepted">
				By clicking <strong>register</strong>, you agree to our <a href="<?php echo $this->getUrl('terms-and-conditions')?>">Terms & Conditions </a>and that you have read our <a href="<?php echo $this->getUrl('privacy-policy')?>">Privacy Policy</a>
			</div>
			<div class="clearer"></div>
			<div class="buttons-set a-right">
				<button type="submit" id="registerBtn" title="<?php echo $this->__('register') ?>" class="button"><span><span><?php echo $this->__('register') ?></span></span></button>
				<div class="clearer"></div>
				<p class="">Need help? </p>
				<p class="">Call<span class="telephone"> 6285 0320</span> or email the Gobbler Team at <a href="mailto:customercare@gobblershop.com">customercare@gobblershop.com</a>.</p>
			</div> 
        <?php if (Mage::helper('checkout')->isContextCheckout()): ?>
            <input name="context" type="hidden" value="checkout" />
        <?php endif; ?>
			</div> 
     
	</div>
    </form>
	
	<?php 
		$customerGroups = Mage::getModel('customer/group')->getCollection()
			->addFieldToFilter('domain', array('notnull' => true));
			
		if($customerGroups->getSize() > 0):
			$domains = array();
			$patterns = array('/-/','/\./');
			$replacements = array('\\-','\\.');
			foreach($customerGroups as $item){			
				$domains[] = '('.preg_replace($patterns,$replacements,$item->getDomain()).')';
			}
			// var_dump($domains);
			$stringDomains = base64_encode(implode('|',$domains));			
	?>
<script>
	validateDomain('<?php echo $stringDomains?>');
</script>
	<?php endif;?>
    <script type="text/javascript">
    //<![CDATA[
		//add validetion confirm email
		Validation.add('validate-email-confirm', 'Emails don\'t match!', function (v) {
			var matchEmail = false;
			if(v === $('email_address').value)
				matchEmail = true;			
			return Validation.get('IsEmpty').test(v) || matchEmail;
		});
		
        var dataForm = new VarienForm('form-validate', true);
        <?php if($this->getShowAddressFields()): ?>
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
        <?php endif; ?>      
    //]]>
    </script>
</div>